package com.aos.eap.adapter;

import android.widget.RadioButton;

import com.aos.eap.R;
import com.aos.eap.bean.DownRecipeBean;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import androidx.annotation.Nullable;


public class RecipeSearchListAdapter extends BaseQuickAdapter<DownRecipeBean, BaseViewHolder> {
    private int layoutPosition; //记录当前点击位置

    public RecipeSearchListAdapter(@Nullable List<DownRecipeBean> data) {
        super(R.layout.adapter_recipe_search_list, data);
    }


    @Override
    protected void convert(BaseViewHolder helper, final DownRecipeBean item) {
        helper.setText(R.id.tvEqpType, item.getEqpType());
        helper.setText(R.id.tvRecipeId, item.getRecipeID());
        helper.setText(R.id.tvRecipeVersion, item.getRecipeVersion());
        helper.setText(R.id.tvStatus, item.getRecipeState());
        this.setOnItemClickListener((adapter, view, position) -> {
            layoutPosition = position;
            notifyDataSetChanged();
        });
        RadioButton rbSelect = helper.getView(R.id.rbSelect);
        rbSelect.setOnClickListener(v -> {
            layoutPosition = helper.getLayoutPosition();
            notifyDataSetChanged();
        });
        if (layoutPosition == helper.getLayoutPosition()) {
            item.setSelect(true);
            rbSelect.setChecked(true);
        } else {
            item.setSelect(false);
            rbSelect.setChecked(false);
        }
    }
}
